package com.yunji.web.common;

import com.yunji.base.business.TextRecordBusiness;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.model.dto.TextRecordDTO;
import com.yunji.common.model.vo.TextRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "管理端-文本记录管理")
@RestController
@RequestMapping("/text")
public class TextRecordController {

    @Resource
    private TextRecordBusiness business;

    @PostMapping("/create")
    @ApiOperation("/新增文本记录")
    public Response<Long> create(@RequestBody TextRecordDTO dto) {
        return ResponseHelper.success(business.create(dto));
    }

    @GetMapping("/getInfo/{id}")
    @ApiOperation("获取文本详情")
    public Response<TextRecordVO> getInfo(@PathVariable Long id){
        return ResponseHelper.success(business.getInfo(id));
    }

    @PutMapping("/edit")
    @ApiOperation("编辑文本详情")
    public Response<String> edit(@RequestBody TextRecordDTO dto){
        business.edit(dto);
        return ResponseHelper.success("修改成功");
    }

    @GetMapping("/list")
    @ApiOperation("获取列表")
    public Response<List<TextRecordVO>> list(TextRecordDTO dto){
        return ResponseHelper.successWithPage(business.list(dto));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除单个文本")
    public Response<String> delete(@PathVariable("id") Long id){
        business.delete(id);
        return ResponseHelper.success();
    }

}
